<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
  	<jsp:include page="../js_top.jsp"></jsp:include>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	  <style type="text/css">
		  .table_report{width:540px;margin:15px auto;}
		  .table_report tr td{line-height:31px;color:#63666d;font-size:14px;font-family:Arial,Helvetica,"微软雅黑";}
		  .table_report tr td a{width:185px;height:38px;line-height:38px;-webkit-border-radius:5px;border-radius:5px;border-color:#b7bacb;display:block;font-size:14px;font-family:"微软雅黑";text-shadow:0 0px 0 rgba(0,0,0,0)!important;background:#b7bacb url(/static/img/images/table_report_icon1.png) no-repeat 70px center;text-align:center;color:#fff;cursor:pointer;text-indent:20px;float:left;margin:0 20px 0 0;}

		  .table_report tr td a:hover,.table_report tr:last-child td:last-child a:hover{background-color:#0fb1d6;text-decoration:none;}
		  input:focus:invalid:focus, textarea:focus:invalid:focus, select:focus:invalid:focus{border-color:#f59942;}
	  </style>
  

  </head>
  
  <body>
    <form action="sys/sysUser/save.do" id="saveForm" name="saveForm" method="post">
    	<input type="hidden" name="userId" id="userId" value="${user.userId}" />
    	<table class="table  table-striped table-hover table_report">
    			<tr>
    				<td >登陆账号</td>
    				<td><input type="text" name="loginName" id="loginName" value="${user.loginName}" placeholder="必填"  required="true"/></td>
    				<td>姓名</td><td>
    				<input type="text" name="userName" id="userName" value="${user.userName}" placeholder="必填"  required="true"/></td>
    			</tr>
    			<tr>
    				<td>性别</td>
    				<td><input type="text" name="sex" id="sex" value="${user.sex}" placeholder="选填"/></td>
    				<td>年龄</td><td>
    				<input type="text" name="age" id="age" value="${user.age}" placeholder="选填" /></td>
    			</tr>
    			<tr>
    				<td>电话</td>
    				<td><input type="text" name="phone" id="phone" value="${user.phone}" placeholder="选填"/></td>
    				<td>备注</td>
    				<td><input type="text" name="remark" id="remark" value="${user.remark}" placeholder="选填"/></td>
    			</tr>
    			<tr>
					<td colspan="10">
						<a  style="margin-left: 66px"  href="javascript:save();">确定</a>
						<a href="javascript:top.Dialog.close();">取消</a>
					</td>

				</tr>
    	</table>
    </form>
  </body>
  <script type="text/javascript">
  $(function($){
  	var userId=$('#userId').val();
  	if(userId !=null && userId != ""){
  		$('#loginName').attr({readonly:"true"});
  	};
  
  });
  function save(){
  	var loginName = $('#loginName').val().trim();
  	var loginNameIs = "${user.loginName}";//存在账号则更新
  	var userName = $('#userName').val().trim();
  	if(loginName === null || loginName === ''){
  		$('#loginName').tips({
  			side:3,
  			msg:'用户名不能为空！',
  			bg:'#AE81FF',
  			time:3
  		});
  		$('#loginName').focus();
  		return false;
  	}
  	if(userName === null || userName === ''){
  		$('#userName').tips({
  			side:3,
  			msg:'姓名不能为空！',
  			bg:'#AE81FF',
  			time:3
  		});
  		$('#userName').focus();
  		return false;
  	}	
  	if((loginNameIs !=null && loginNameIs != '' && loginNameIs != loginName) || loginNameIs === null || loginNameIs === ''){
		var url = '<%=basePath%>sys/sysUser/checkLoginNameExist.do';
		var postData;
		postData = {"loginName":loginName};
		$.post(url,postData,function(data){
			if(data && data==="existUser"){
				
				$("#loginName").tips({
					side : 3,
					msg : "该账号已存在!",
					bg : '#FF5080',
					time : 3
				});
				
			}else{
				$.ajax({
	             cache: true,
	             type: "POST",
	             url:'<%=basePath%>sys/sysUser/save.do',
	             data:$('#saveForm').serialize(),
	             async: false,
	             error: function(request) {
	             	layer.msg('<span style="color:white;">插入数据出错 !</span>');
	             },
	             success: function(data) {
	             	if(data=true){
	             		top.Dialog.close();
	                }
	             }
         		});
			}
		});
	}else{
		$.ajax({
             cache: true,
             type: "POST",
             url:'<%=basePath%>sys/sysUser/save.do',
             data:$('#saveForm').serialize(),
             async: false,
             error: function(request) {
             layer.msg('<span style="color:white;">更新数据出错 !</span>');
             },
             success: function(data) {
             	if(data=true){
                	top.Dialog.close();
                }
             }
         });
	}

  	
  }
  </script>
</html>
